package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SyCourseCategory;
import com.ruoyi.siyun.service.ISyCourseCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 课程分类Controller
 * 
 * @author ruoyi
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/siyun/category")
public class SyCourseCategoryController extends BaseController
{
    @Autowired
    private ISyCourseCategoryService syCourseCategoryService;

    /**
     * 查询课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:list')")
    @GetMapping("/list")
    public AjaxResult list(SyCourseCategory syCourseCategory)
    {
        List<SyCourseCategory> list = syCourseCategoryService.selectSyCourseCategoryList(syCourseCategory);
        return success(list);
    }


    @GetMapping("/collectNum")
    public AjaxResult collectNum(SyCourseCategory syCourseCategory) {
        Integer collectNum = syCourseCategoryService.selectSyCourseCollectNum(syCourseCategory);
        return success(collectNum);
    }

    /**
     * 导出课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:export')")
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyCourseCategory syCourseCategory)
    {
        List<SyCourseCategory> list = syCourseCategoryService.selectSyCourseCategoryList(syCourseCategory);
        ExcelUtil<SyCourseCategory> util = new ExcelUtil<SyCourseCategory>(SyCourseCategory.class);
        util.exportExcel(response, list, "课程分类数据");
    }

    /**
     * 获取课程分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(syCourseCategoryService.selectSyCourseCategoryByCategoryId(categoryId));
    }

    /**
     * 新增课程分类
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:add')")
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyCourseCategory syCourseCategory)
    {
        return toAjax(syCourseCategoryService.insertSyCourseCategory(syCourseCategory));
    }

    /**
     * 修改课程分类
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:edit')")
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyCourseCategory syCourseCategory)
    {
        return toAjax(syCourseCategoryService.updateSyCourseCategory(syCourseCategory));
    }

    /**
     * 删除课程分类
     */
    @PreAuthorize("@ss.hasPermi('siyun:category:remove')")
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(syCourseCategoryService.deleteSyCourseCategoryByCategoryIds(categoryIds));
    }

    /**
     * 获取课程分类树列表
     */
    @PreAuthorize("@ss.hasPermi('siyun:user:courseCategoryTree')")
    @GetMapping("/courseCategoryTree")
    public AjaxResult deptTree(SyCourseCategory symbolCategory)
    {
        return success(syCourseCategoryService.selectCourseCategoryTreeList(symbolCategory));
    }
}
